<%@ include file="/jsp/common.jsp" %>
<%@ page  language="java" import="java.util.*" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<head>
<link href="../../css/mainbody_style.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="../../js/jquery-1.4.4.js" ></script>
<style type="text/css">
tr>td:nth-child(2n-1){text-align:right;}

</style>
</head>
<body>
<div style="width:90%;">
	<form method="post" id="formClass" >
		<input type="hidden" name="position" id="position" value='<c:out value="${position}"/>' />
		<table style="width:100%;table-layout:fixed;line-height:4em;">
			<tr>
				<td>学校：</td>
				<td>
					<input type="text" disabled="disabled"  style="color:blue;background-color:#f4f4f4;font-size:1.1em;"
						name="schoolName" value="<c:out value='${schoolName}'/>" />
				</td>
				<td>年级：</td>
				<td>
					<select name="gradeCode" id="gradeCode" onchange="chgClass()">
						<c:forEach items="${gradeList }" var="grade">
							<option value="<c:out value='${grade.dicCode}'/>"> <c:out value="${grade.dicValue }"/> 
						</c:forEach>
					</select>
				</td>
				<td>班级：</td>
				<td>
					<select name="classCode" id="classCode">
						<c:forEach items="${classList }" var="cla">
							<option value="<c:out value='${cla.column02}'/>"> <c:out value="${cla.column01}"/>班
						</c:forEach>
					</select>
				</td>
				
			</tr>
			<tr>
				<td>学生姓名：</td>
				<td>
					<input type="text" name="studentName" id="studentName" />
				</td>
				<td>性别：</td>
				<td>
					<input type="radio" name="gender" value="F"/>女
					<input type="radio" name="gender" value="M" checked="checked"/>男
				</td>
				<td>联系电话：</td>
				<td>
					<input type="text" name="telNo" id="telNo" />
				</td>
			</tr>
			<tr>
				<td colspan="6" style="text-align:center;">
					<input type="button" class="button_sub01" value="提交保存" onclick="saveData()"/>
				</td>
			</tr>
		</table>
	</form>
</div>

<script>
function chgClass(){
	var position =  $("#position").val();
	var gradeCode = $("#gradeCode").val();
	$.ajax({
		url:"../../commonAjax.do",
		type:"post",
		data:{
			"position":position,
			"gradeLevel":gradeCode,
			"sql":"school.queryExistSeniorClass"
		},
		success:function(data){
			var resuleCode = data["result"];
			if(resuleCode=="0") return;
			var resList = data["resList"];
			if(resList || resList.length>0){
				$("#classCode").empty();
				for(ind in resList){
					var content = "<option value='"+ resList[ind]["column02"] +"'>" +resList[ind]["column01"] + "班"
					$("#classCode").append(content);
				}
			}
		}
	});
}
//保存学生信息
function saveData(){
	var studentName = $("#studentName").val();
	var telNo = $("#telNo").val();
	if(studentName && telNo){
		//校验号码是否为11位的电话
		if(!(/^1\d{10}$/.test(telNo))){
			alert("手机号为以1开头的11位长度数字");
			return;
		}
		//校验号码是否为11位的电话
		if(!(/^[\u4e00-\u9fa5 ]{2,10}$/.test(studentName))){
			alert("名字必须为2-10个长度的中文");
			return;
		}
		$.ajax({
			url:"SaveStudentInfo.do",
			type:"post",
			dataType:"text",
			data:$("#formClass").serialize(),
			success:function(data){
				var resCode = data;
				if(resCode=="01"){
					alert("数据保存成功");
				}else if(resCode=="02"){
					alert("学生已经存在");
				}else if(resCode=="03"){
					alert("数据保存失败");
				}
			},
			error:function(){
				alter("保存失败");
			}
		});
	}else{
		alert("请将信息填充完整");
		return;
	}
}
</script>
</body>